<?php

namespace App\Http\Controllers\System;

use App\Common\Utils\JsonResponse;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;

class ActivityController extends Controller
{
    /** @var \App\Services\System\LogService $logService */
    private $logService;
    /** @var \App\Services\System\ActivityService $activityService */
    private $activityService;

    /**
    * Create a new controller instance.
    *
    * @return void
    */
    public function __construct()
    {
        parent::__construct();
        $this->middleware('auth');
        $this->logService = app('logService');
        $this->activityService = app('activityService');
    }

    /**
     * @Description: 获取活动列表信息数据
     * @Author: kzj
     * @datetime: 2023-02-21
     */
    public function getList(Request $request)
    {
        try
        {
            $result = $this->activityService->getList($request->all());
            //不走日志 lxy
            if(!isset($request->all()['is_log']) ){
                $logInfo = $this->activityService->getLogInfo($request->form_key, 'list', $request->all());
                $this->logService->log($logInfo['id'], $logInfo['title'], $logInfo['content']);
            }

            return JsonResponse::get($result['data'], TRUE, $result['total'], $result['per_page']);
        }
        catch(\Exception $e)
        {
            return $this->error($e);
        }
    }

    //经验交流
    public function getJyjlList(Request $request)
    {
        try{
            $result = $this->activityService->getJyjlList($request->all());
            return JsonResponse::get($result['data'], TRUE, $result['total'], $result['per_page']);
        }catch(\Exception $e){
            return $this->error($e);
        }
    }

    //课题研究
    public function getKtyjList(Request $request)
    {
        try{
            $result = $this->activityService->getKtyjList($request->all());
            return JsonResponse::get($result['data'], TRUE, $result['total'], $result['per_page']);
        }catch(\Exception $e){
            return $this->error($e);
        }
    }

    //论文发表
    public function getLwfbList(Request $request)
    {
        try{
            $result = $this->activityService->getLwfbList($request->all());
            return JsonResponse::get($result['data'], TRUE, $result['total'], $result['per_page']);
        }catch(\Exception $e){
            return $this->error($e);
        }
    }

    //论著发表
    public function getLzfbList(Request $request)
    {
        try{
            $result = $this->activityService->getLzfbList($request->all());
            return JsonResponse::get($result['data'], TRUE, $result['total'], $result['per_page']);
        }catch(\Exception $e){
            return $this->error($e);
        }
    }

    /**
     * @Description: 获取课题研究活动列表信息数据
     * @Author: kzj
     * @datetime: 2023-02-21
     */
    public function getStudyList(Request $request)
    {
        try
        {
            $result = $this->activityService->getStudyList($request->all());

            $logInfo = $this->activityService->getLogInfo($request->form_key, 'list', $request->all());
            $this->logService->log($logInfo['id'], $logInfo['title'], $logInfo['content']);

            return JsonResponse::get($result['data'], TRUE, $result['total'], $result['per_page']);
        }
        catch(\Exception $e)
        {
            return $this->error($e);
        }
    }


    /**
     * @Description: 活动添加
     * @Author: kzj
     * @datetime: 2023-02-28
     */
    public function add(Request $request)
    {
        try{
            $result = $this->activityService->add($request->all());

            $logInfo = $this->activityService->getLogInfo($request->activity_category, 'add', $request->all());
            $this->logService->log($logInfo['id'], $logInfo['title'], $logInfo['content']);

            return JsonResponse::success($result,'操作成功');
        }catch(\Exception $e){
            return $this->error($e);
        }
    }

    /**
     * @Description: 活动单条数据
     * @Author: kzj
     * @datetime: 2023-02-28
     */
    public function one(Request $request)
    {
        try{
            $result = $this->activityService->one($request->all());
            return JsonResponse::success($result,'操作成功');
        }catch(\Exception $e){
            return JsonResponse::error($e->getMessage());
        }
    }

    /**
     * @Description: 活动编辑
     * @Author: kzj
     * @datetime: 2023-02-28
     */
    public function edit(Request $request)
    {
        try{
            $result = $this->activityService->edit($request->all());

            $logInfo = $this->activityService->getLogInfo($request->activity_category, 'edit', $request->all());
            $this->logService->log($logInfo['id'], $logInfo['title'], $logInfo['content']);

            return JsonResponse::success($result,'操作成功');
        }catch(\Exception $e){
            return JsonResponse::error($e->getMessage());
        }
    }

    /**
     * @Description: 活动审核
     * @Author: kzj
     * @datetime: 2023-02-28
     */
    public function check(Request $request)
    {
        try{
            $result = $this->activityService->check($request->all());

            $logInfo = $this->activityService->getLogInfo($request->activity_category, 'check', $request->all());
            $this->logService->log($logInfo['id'], $logInfo['title'], $logInfo['content']);

            return JsonResponse::success($result,'操作成功');
        }catch(\Exception $e){
            return JsonResponse::error($e->getMessage());
        }
    }

    /**
     * @Description: 活动删除
     * @Author: kzj
     * @datetime: 2023-02-28
     */
    public function del(Request $request)
    {
        try{
            $result = $this->activityService->del($request->all());

            $logInfo = $this->activityService->getLogInfo($request->activity_category, 'del', $request->all());
            $this->logService->log($logInfo['id'], $logInfo['title'], $logInfo['content']);

            return JsonResponse::success($result,'操作成功');
        }catch(\Exception $e){
            return JsonResponse::error($e->getMessage());
        }
    }

    /**
     * @Description: 申报上传数据
     * @Author: kzj
     * @datetime: 2023-03-14
     */
    public function uploadStage(Request $request)
    {
        try{
            $result = $this->activityService->uploadStage($request->all());
            $this->logService->log('229', '课题研究上传', '课题研究上传');
            return JsonResponse::success($result,'操作成功');
        }catch(\Exception $e){
            return JsonResponse::error($e->getMessage());
        }
    }

    /**
     * @Description: 申报审核数据
     * @Author: kzj
     * @datetime: 2023-03-14
     */
    public function checkStage(Request $request)
    {
        try{
            $result = $this->activityService->checkStage($request->all());
            $this->logService->log('227', '课题研究审核', '课题研究审核');
            return JsonResponse::success($result,'操作成功');
        }catch(\Exception $e){
            return JsonResponse::error($e->getMessage());
        }
    }

    /**
     * @Description: 生成相关文件数据
     * @Author: kzj
     * @datetime: 2023-05-31
     */
    public function generateStage(Request $request)
    {
        try{
            $result = $this->activityService->generateStage($request->all());
            $this->logService->log('229', '课题研究生成证书', '课题研究生成证书');
            return JsonResponse::success($result,'操作成功');
        }catch(\Exception $e){
            return JsonResponse::error($e->getMessage());
        }
    }

    public function push(Request $request)
    {
        try{
            $result = $this->activityService->push($request->all());
            return JsonResponse::success($result,'操作成功');
        }catch(\Exception $e){
            return JsonResponse::error($e->getMessage());
        }
    }

    public function pushOne(Request $request)
    {
        try{
            $result = $this->activityService->pushOne($request->all());
            return JsonResponse::success($result,'操作成功');
        }catch(\Exception $e){
            return JsonResponse::error($e->getMessage());
        }
    }
}
